package com.kuanter.kuanterauto.entity;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.kuanter.kuanterauto.utils.StringUtils;
/**
 * 卡片信息数据
 * @author soup
 *
 */
public class CardInfoList {

	/**
	 * 
	 */
	public static final String TAG = "CardInfoList";

	private List<CardInfo> carinfos = null;

	// {"status":true,
	// "cardInfoList":[{
	// "accountList":[{"accountTypeName":"积分","balance":60,"customerGroupName":"人保郑州电子商务部","expireTime":"2013-10-12"}],
	// "activationTime":"2012-10-25 18:07:32","cardNumber":"11001261","cardPicPath":"\/resources\/cardTypePicture\/31859420121211094600.png","cardState":"正常"}]}
	public CardInfoList(String json) {
		try {
			JSONObject jobj = new JSONObject(json);
			if (StringUtils.isSuccess(json)) {
				JSONArray jarr = jobj.optJSONArray("cardInfoList");
				if (jarr != null && jarr.length() > 0) {
					carinfos = new ArrayList<CardInfo>();
					for (int i = 0; i < jarr.length(); i++) {
						JSONObject jo = jarr.optJSONObject(i);
						CardInfo carinfo = new CardInfo();
						carinfo.setActivationTime(jo
								.optString("activationTime"));
						carinfo.setCardNumber(jo.optString("cardNumber"));
						carinfo.setCardPicPath(jo.optString("cardPicPath"));
						carinfo.setCardState(jo.optString("cardState"));

						JSONArray ja = jo.optJSONArray("accountList");
						if (ja != null && ja.length() > 0) {
							List<AccountList> accoutlists = new ArrayList<AccountList>();
							for (int j = 0; j < ja.length(); j++) {
								JSONObject o = ja.optJSONObject(j);
								AccountList accoutlist = new AccountList();
								accoutlist.setAccountTypeName(o
										.optString("accountTypeName"));
								accoutlist.setBalance(o.optString("balance"));
								accoutlist.setCustomerGroupName(o
										.optString("customerGroupName"));
								accoutlist.setExpireTime(o
										.optString("expireTime"));
								accoutlists.add(accoutlist);
								carinfo.setAccoutlists(accoutlists);
							}
						}

						// System.out.println(carinfo.getAccoutlists());

						carinfos.add(carinfo);
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public List<CardInfo> getCarinfos() {
		return carinfos;
	}

}
